package com.irdstudio.efp.report.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.loan.service.vo.AccLoanVO;
import com.irdstudio.efp.report.service.dao.ZxbsAccLoanDao;
import com.irdstudio.efp.report.service.domain.ZxbsAccLoan;
import com.irdstudio.efp.report.service.facade.ZxbsAccLoanService;
import com.irdstudio.efp.report.service.vo.ZxbsAccLoanVO;
import com.sun.org.apache.regexp.internal.RE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 贷款台账服务实现
 *
 * @author gcb
 * @date 2020-07-28
 */
@Service("zxbsAccLoanService")
public class ZxbsAccLoanServiceImpl implements ZxbsAccLoanService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(ZxbsAccLoanServiceImpl.class);

    @Autowired
    private ZxbsAccLoanDao zxbsAccLoanDao;

    /**
     * 新增数据
     *
     * @param zxbsAccLoanVo
     * @return
     */
    @Override
    public int insert(ZxbsAccLoanVO zxbsAccLoanVo) {
        logger.debug("当前新增数据为:" + zxbsAccLoanVo.toString());
        int num = 0;
        try {
            ZxbsAccLoan zxbsAccLoan = new ZxbsAccLoan();
            beanCopy(zxbsAccLoanVo, zxbsAccLoan);
            num = zxbsAccLoanDao.insert(zxbsAccLoan);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param zxbsAccLoanVo
     * @return
     */
    @Override
    public int deleteByPk(ZxbsAccLoanVO zxbsAccLoanVo) {
        logger.debug("当前删除数据条件为:" + zxbsAccLoanVo);
        int num = 0;
        try {
            ZxbsAccLoan zxbsAccLoan = new ZxbsAccLoan();
            beanCopy(zxbsAccLoanVo, zxbsAccLoan);
            num = zxbsAccLoanDao.deleteByPk(zxbsAccLoan);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + zxbsAccLoanVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param zxbsAccLoanVo
     * @return
     */
    @Override
    public int updateByPk(ZxbsAccLoanVO zxbsAccLoanVo) {
        logger.debug("当前修改数据为:" + zxbsAccLoanVo.toString());
        int num = 0;
        try {
            ZxbsAccLoan zxbsAccLoan = new ZxbsAccLoan();
            beanCopy(zxbsAccLoanVo, zxbsAccLoan);
            num = zxbsAccLoanDao.updateByPk(zxbsAccLoan);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + zxbsAccLoanVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inZxbsAccLoanVo
     * @return
     */
    @Override
    public ZxbsAccLoanVO queryByPk(ZxbsAccLoanVO inZxbsAccLoanVo) {
        logger.debug("当前查询参数信息为:" + inZxbsAccLoanVo);
        try {
            ZxbsAccLoan queryZxbsAccLoan = new ZxbsAccLoan();
            beanCopy(inZxbsAccLoanVo, queryZxbsAccLoan);
            ZxbsAccLoan queryRslZxbsAccLoan = zxbsAccLoanDao.queryByPk(queryZxbsAccLoan);
            if (Objects.nonNull(queryRslZxbsAccLoan)) {
                return beanCopy(queryRslZxbsAccLoan, new ZxbsAccLoanVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public int insertOrUpdate(List<ZxbsAccLoanVO> list) throws Exception {
        return zxbsAccLoanDao.insertOrUpdate((List<ZxbsAccLoan>) beansCopy(list, ZxbsAccLoan.class));
    }

    @Override
    public List<ZxbsAccLoanVO> queryByBillNos(List<String> billNos) throws Exception {
        return (List<ZxbsAccLoanVO>) beansCopy(this.zxbsAccLoanDao.queryByBillNos(billNos), ZxbsAccLoanVO.class);
    }

    @Override
    public List<ZxbsAccLoanVO> queryByApplySqes(List<String> ids) throws Exception {
        return (List<ZxbsAccLoanVO>) beansCopy(zxbsAccLoanDao.queryByApplySqes(ids), ZxbsAccLoanVO.class);
    }
}
